/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl;

import bl.SalaryBO;
import entities.Salary;
import java.util.Vector;
import model.SalaryDetailListModel;

/**
 *
 * @author MinhDuc
 */
public class SalaryDetail extends javax.swing.JDialog {

    /**
     * Creates new form SalaryDetail
     */
    SalaryDetailListModel model;
    SalaryBO salaryBO = new SalaryBO();
    Vector<Salary> data = new Vector<Salary>();

    public SalaryDetail(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();

        data = salaryBO.getData();
        listSalary.setModel(new SalaryDetailListModel(data));

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        listSalary = new javax.swing.JList();
        lblSalaryGrade = new javax.swing.JLabel();
        lblSalaryPerHour = new javax.swing.JLabel();
        lblDescription = new javax.swing.JLabel();
        txtSalaryGrade = new javax.swing.JTextField();
        txtSalaryPerHour = new javax.swing.JTextField();
        txtDescription = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        listSalary.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Salary Detail", javax.swing.border.TitledBorder.LEADING, javax.swing.border.TitledBorder.ABOVE_TOP));
        listSalary.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        listSalary.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listSalaryValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(listSalary);

        lblSalaryGrade.setText("Salary Grade:");

        lblSalaryPerHour.setText("Salary Per Hour:");

        lblDescription.setText("Description:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lblSalaryPerHour, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblDescription, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblSalaryGrade, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtSalaryGrade)
                    .addComponent(txtSalaryPerHour)
                    .addComponent(txtDescription, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblSalaryGrade)
                            .addComponent(txtSalaryGrade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblSalaryPerHour)
                            .addComponent(txtSalaryPerHour, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblDescription)
                            .addComponent(txtDescription, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void listSalaryValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listSalaryValueChanged
        // TODO add your handling code here:
        Salary salary = data.get(listSalary.getSelectedIndex());
        txtSalaryGrade.setText(salary.getSalaryGrade());
        txtSalaryPerHour.setText(String.valueOf(salary.getSalaryPerHour()));
        txtDescription.setText(salary.getDescription());
    }//GEN-LAST:event_listSalaryValueChanged
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblDescription;
    private javax.swing.JLabel lblSalaryGrade;
    private javax.swing.JLabel lblSalaryPerHour;
    private javax.swing.JList listSalary;
    private javax.swing.JTextField txtDescription;
    private javax.swing.JTextField txtSalaryGrade;
    private javax.swing.JTextField txtSalaryPerHour;
    // End of variables declaration//GEN-END:variables
}
